#!/usr/bin/env python
# -*- encoding: utf-8 -*-

'''
@File    :   test.py  
@Version : 1.0  
@Author :   iherr
@Desciption : None
'''

import bayes
import numpy as np

if __name__ == '__main__':

    postingList, classVec = bayes.loadDataSet()
    print('postingList:\n',postingList)
    myVocabList = bayes.createVocabList(postingList)
    print('myVocabList:\n',myVocabList)
    trainMat = []
    for postinDoc in postingList:
        trainMat.append(bayes.setOfWords2Vec(myVocabList, postinDoc))
    print('trainMat:\n', trainMat)

    p0V, p1V, pAb = bayes.trainNB0(trainMat, classVec)
    print('p0V:\n', p0V)
    print('p1V:\n', p1V)
    print('classVec:\n', classVec)
    print('pAb:\n', pAb)

    testEntry = ['love', 'my', 'dalmation']  # 测试样本1
    thisDoc = np.array(bayes.setOfWords2Vec(myVocabList, testEntry))  # 测试样本向量化
    if bayes.classifyNB(thisDoc, p0V, p1V, pAb):
        print(testEntry, '属于侮辱类')  # 执行分类并打印分类结果
    else:
        print(testEntry, '属于非侮辱类')  # 执行分类并打印分类结果
    testEntry = ['stupid', 'garbage']  # 测试样本2

    thisDoc = np.array(bayes.setOfWords2Vec(myVocabList, testEntry))  # 测试样本向量化
    if bayes.classifyNB(thisDoc, p0V, p1V, pAb):
        print(testEntry, '属于侮辱类')  # 执行分类并打印分类结果
    else:
        print(testEntry, '属于非侮辱类')